// pages/Generalhospital/Branchdetails/Branchdetails.js
var app = getApp();
var Api = require("../../../api/method.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    branchid:"",
    arr:[],
    branchname:"",
    salesmanList:"",
    user:""
  },
//更多
  Openmore:function(e){
    wx.navigateTo({
      url: "/pages/Generalhospital/more/more?branchid=" + e.currentTarget.dataset.branchid,
    })
  },
  //跳转订单详情页
  branchdetails:function(){
    wx.navigateTo({
      url: "/pages/Generalhospital/branchdetail/branchdetail",
    })
  },
  //业务员详情
  listdetails: function (e) {
    let openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: "/pages/Generalhospital/branchdetail/branchdetail?openid=" + openid,
    })
  },
  //搜索值
  getUsername: function (e) {
    this.setData({
      user: e.detail.value
    })
    if (this.data.user == "") {
      this.Salesmanlist();
    }
  },
  //概览搜索
  Search: function (e) {
    let that = this;
    if (that.data.user == "") {
      wx.showToast({
        icon: "none",
        duration: 1500,
        title: "请输入搜索内容"
      })
      return
    }
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let list = {
      pageNo: 1,
      branchId: that.data.branchid,
      pageSize: 20,
      nickName: that.data.user
    };
    console.log(list);
    Api.Salesmanlist(list, function (err, res) {
      if (res.data.code == 1) {
        that.setData({
          Salesmanlist: res.data.data
        });
        wx.hideLoading();
      }
    }); 
    // let list = {
    //   nickName: that.data.user
    // };
    // console.log(list);
    // Api.searchSalesman(list, function (err, res) {
    //   console.log(res.data);
    //   if (res.data.code == 1) {
    //     that.setData({
    //       Salesmanlist: res.data.data
    //     })
    //     wx.hideLoading();
    //   }
    // });
  },
  //分院概览
  branchgailan: function () {
    wx.showToast({
      title: '加载中',
      icon: 'loading'
    });
    let that = this;
    let list = {
      branchId: that.data.branchid
    };
    Api.branch(list, function (err, res) {
      console.log(res.data)
      if (res.data.code == 0) {
        wx.showToast({
          title: '登录失败',
          icon: 'fail',
          duration: 2000
        })
      } else {
        let Arr = res.data.data;
        that.data.arr.push(Arr);
        that.setData({
          arr: that.data.arr,
          salesmanList: res.data.data.salesmanList
        })
      }
      wx.hideToast();
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.setData({
      branchid:options.branchid,
      branchname:options.branchName
    });
    this.branchgailan();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})